package com.xl.generator.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.xl.generator.common.ActionResult;
import com.xl.generator.common.ActionResultService;
import com.xl.generator.domain.CommonUser;
import com.xl.generator.domain.CompetitionDetail;
import com.xl.generator.domain.CompetitionRecord;
import com.xl.generator.domain.CompetitionScheme;
import com.xl.generator.dto.CompetitionRecordDto;
import com.xl.generator.dto.CompetitionSchemeDto;
import com.xl.generator.mapper.CompetitionRecordMapper;
import com.xl.generator.mapper.CompetitionSchemeMPJMapper;
import com.xl.generator.mapper.CompetitionSchemeMapper;
import com.xl.generator.pojo.PageList;
import com.xl.generator.service.CompetitionSchemeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 〈〉<br>
 *
 * @author lvln5
 * @Description
 * @date 2022/11/12 19:39
 */
@Api(value = "赛事信息的增删改查")
@RestController
@RequestMapping("competitionScheme")
public class CompetitionSchemeController {
	@Resource
	private CompetitionSchemeService competitionSchemeService;
	@ApiOperation(value = "分页查询所有赛事", notes="")
	@PostMapping ("list")
	public ActionResult test(@RequestParam("current") Integer current,@RequestParam("Size") Integer size){
		IPage<CompetitionScheme> choiceQuestion = new Page<>();
		choiceQuestion.setCurrent(current);
		choiceQuestion.setSize(size);
		List list = competitionSchemeService.listAll(choiceQuestion);
		PageList pageList = new PageList();
		pageList.setTotal(choiceQuestion.getTotal());
		pageList.setData(list);
		return ActionResultService.callBackResultOK(pageList);
	}

	/**
	 * @param choiceQuestion
	 * @return {@code ActionResult }
	 */
	@ApiOperation(value = "添加赛事", notes="注册成功状态码为o,否侧为-1失败")
	@PostMapping("add")
	public ActionResult register(@RequestBody @Validated CompetitionScheme choiceQuestion){
		boolean save = competitionSchemeService.save(choiceQuestion);
		if (save){
			return ActionResultService.callBackResultOK("添加成功");
		}
		return ActionResultService.callBackResultOK("添加失败");
	}
	@ApiOperation(value = "通过类型查看赛事CompetitionId", notes="注册成功状态码为o,否侧为-1失败 getCompetitionId")
	@PostMapping("listByType")
	public ActionResult register(@RequestParam("current") Integer current,@RequestParam("Size") Integer size,
			@RequestBody CompetitionScheme competitionScheme){
		IPage<CompetitionScheme> choiceQuestion = new Page<>();
		choiceQuestion.setCurrent(current);
		choiceQuestion.setSize(size);

		List<CompetitionSchemeDto> list = competitionSchemeService.listByType(choiceQuestion, competitionScheme.getCompetitionId());
		PageList pageList = new PageList();
		pageList.setTotal(choiceQuestion.getTotal());
		pageList.setData(list);
		return ActionResultService.callBackResultOK(pageList);
	}
	/**
	 * @param
	 * @return {@code ActionResult }
	 */
	@ApiOperation(value = "删除赛事", notes="删除成功状态码为o,否侧为-1失败")
	@PostMapping("del")
	public ActionResult del(@RequestBody CompetitionScheme choiceQuestion){
		LambdaQueryWrapper<CompetitionScheme> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(CompetitionScheme::getId,choiceQuestion.getId());
		boolean remove = competitionSchemeService.remove(queryWrapper);
		if (remove){
			return	ActionResultService.callBackResultOK("删除成功");
		}
		return ActionResultService.callBackResultFail("删除失败");
	}
	@ApiOperation(value = "更新赛事", notes="更新成功状态码为o,否侧为-1失败")
	@PostMapping("update")
	public ActionResult updata(@RequestBody CompetitionScheme choiceQuestion){
//		LambdaQueryWrapper<ChoiceQuestion> queryWrapper = new LambdaQueryWrapper<>();
//		queryWrapper.eq(ChoiceQuestion::getId,choiceQuestion.getId());
		boolean update = competitionSchemeService.updateById(choiceQuestion);
		if (update){
			return	ActionResultService.callBackResultOK("更新成功");
		}
		return ActionResultService.callBackResultFail("更新失败");
	}
}
